﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('Ap_CloseBill.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('Ap_CloseBill.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除</a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="cVouchType">单据类型编码</a-select-option>
                <a-select-option key="cVouchID">单据编号</a-select-option>
                <a-select-option key="cDwCode">单位编码</a-select-option>
                <a-select-option key="cDeptCode">部门编码</a-select-option>
                <a-select-option key="cPerson">业务员编码</a-select-option>
                <a-select-option key="cItem_Class">项目大类编</a-select-option>
                <a-select-option key="cItemCode">项目编码</a-select-option>
                <a-select-option key="cSSCode">结算方式编码</a-select-option>
                <a-select-option key="cNoteNo">票据号</a-select-option>
                <a-select-option key="cCoVouchType">对应单据类型</a-select-option>
                <a-select-option key="cCoVouchID">对应单据号</a-select-option>
                <a-select-option key="cDigest">摘要</a-select-option>
                <a-select-option key="cBankAccount">银行账号</a-select-option>
                <a-select-option key="cexch_name">币种名称</a-select-option>
                <a-select-option key="cOperator">录入人</a-select-option>
                <a-select-option key="cCancelMan">核销人</a-select-option>
                <a-select-option key="cRPMan">出纳签字人</a-select-option>
                <a-select-option key="cOrderNo">订单号</a-select-option>
                <a-select-option key="cCode">结算科目编码</a-select-option>
                <a-select-option key="cPreCode">预收付科目编码</a-select-option>
                <a-select-option key="cSrcFlag">结算单来源</a-select-option>
                <a-select-option key="cPzID">凭证线索号</a-select-option>
                <a-select-option key="cFlag">应收应付标志</a-select-option>
                <a-select-option key="csItemCode">结算科目项目</a-select-option>
                <a-select-option key="cCancelNo">现结线索</a-select-option>
                <a-select-option key="cBank">对方银行</a-select-option>
                <a-select-option key="cNatBank">本单位银行名称</a-select-option>
                <a-select-option key="cNatBankAccount">本单位银行账号</a-select-option>
                <a-select-option key="cCheckMan">审核人</a-select-option>
                <a-select-option key="cDefine1">自定义项1</a-select-option>
                <a-select-option key="cDefine2">自定义项2</a-select-option>
                <a-select-option key="cDefine3">自定义项3</a-select-option>
                <a-select-option key="cDefine8">自定义项8</a-select-option>
                <a-select-option key="cDefine9">自定义项9</a-select-option>
                <a-select-option key="cDefine10">自定义项10</a-select-option>
                <a-select-option key="cDefine11">自定义项11</a-select-option>
                <a-select-option key="cDefine12">自定义项12</a-select-option>
                <a-select-option key="cDefine13">自定义项13</a-select-option>
                <a-select-option key="cDefine14">自定义项14</a-select-option>
                <a-select-option key="cItemName">项目名称</a-select-option>
                <a-select-option key="cContractType">合同类型</a-select-option>
                <a-select-option key="cContractID">合同号</a-select-option>
                <a-select-option key="sDLCode">发货单</a-select-option>
                <a-select-option key="cmodifier">修改人</a-select-option>
                <a-select-option key="cbg_auditor">超预算审批人</a-select-option>
                <a-select-option key="cbg_audittime">预算审批时间</a-select-option>
                <a-select-option key="cbg_itemcode">预算项目编码</a-select-option>
                <a-select-option key="cbg_itemname">预算项目名称</a-select-option>
                <a-select-option key="cbg_caliberkey1">预算口径类型1编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname1">预算口径类型1名称</a-select-option>
                <a-select-option key="cbg_caliberkey2">预算口径类型2编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname2">预算口径类型2名称</a-select-option>
                <a-select-option key="cbg_caliberkey3">预算口径类型3编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname3">预算口径类型3名称</a-select-option>
                <a-select-option key="cbg_calibercode1">预算口径1编码</a-select-option>
                <a-select-option key="cbg_calibername1">预算口径1名称</a-select-option>
                <a-select-option key="cbg_calibercode2">预算口径2编码</a-select-option>
                <a-select-option key="cbg_calibername2">预算口径2名称</a-select-option>
                <a-select-option key="cbg_calibercode3">预算口径3编码</a-select-option>
                <a-select-option key="cbg_calibername3">预算口径3名称</a-select-option>
                <a-select-option key="cbg_auditopinion">预算审批结果</a-select-option>
                <a-select-option key="cApplyCode">申请单号</a-select-option>
                <a-select-option key="cPZNum">凭证编号</a-select-option>
                <a-select-option key="cbg_caliberkey4">预算口径类型4编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname4">预算口径类型4名称</a-select-option>
                <a-select-option key="cbg_caliberkey5">预算口径类型5编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname5">预算口径类型5名称</a-select-option>
                <a-select-option key="cbg_caliberkey6">预算口径类型6编码</a-select-option>
                <a-select-option key="cbg_caliberkeyname6">预算口径类型6名称</a-select-option>
                <a-select-option key="cbg_calibercode4">预算口径4编码</a-select-option>
                <a-select-option key="cbg_calibername4">预算口径4名称</a-select-option>
                <a-select-option key="cbg_calibercode5">预算口径5编码</a-select-option>
                <a-select-option key="cbg_calibername5">预算口径5名称</a-select-option>
                <a-select-option key="cbg_calibercode6">预算口径6编码</a-select-option>
                <a-select-option key="cbg_calibername6">预算口径6名称</a-select-option>
                <a-select-option key="cReserveDeptCode">预定部门</a-select-option>
                <a-select-option key="cagentcuscode">委托方编码</a-select-option>
                <a-select-option key="csysbarcode">单据条码</a-select-option>
                <a-select-option key="cCurrentAuditor">当前审批人</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {this.pagination.current = 1; this.getDataList()}">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :scroll="{y:530}"
      :columns="columns"
      :rowKey="(row, index) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="true"
      size="small"
    >
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime) }}</span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a v-if="hasPerm('Ap_CloseBill.Edit')" @click="handleEdit(record.Id)">编辑</a>
          <a-divider v-if="hasPerm('Ap_CloseBill.Edit')&&hasPerm('Ap_CloseBill.Delete')" type="vertical" />
          <a v-if="hasPerm('Ap_CloseBill.Delete')" @click="handleDelete([record.Id])">删除</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import moment from 'moment'
const columns = [
  { title: '单据类型编码', dataIndex: 'cVouchType', align: 'center', width: '10%' },
  { title: '单据编号', dataIndex: 'cVouchID', align: 'center', width: '10%' },
  { title: '单据日期', dataIndex: 'dVouchDate', align: 'center', width: '10%' },
  { title: '会计期间', dataIndex: 'iPeriod', align: 'center', width: '10%' },
  { title: '单位编码', dataIndex: 'cDwCode', align: 'center', width: '10%' },
  { title: '部门编码', dataIndex: 'cDeptCode', align: 'center', width: '10%' },
  { title: '业务员编码', dataIndex: 'cPerson', align: 'center', width: '10%' },
  { title: '项目大类编', dataIndex: 'cItem_Class', align: 'center', width: '10%' },
  { title: '项目编码', dataIndex: 'cItemCode', align: 'center', width: '10%' },
  { title: '结算方式编码', dataIndex: 'cSSCode', align: 'center', width: '10%' },
  { title: '票据号', dataIndex: 'cNoteNo', align: 'center', width: '10%' },
  { title: '对应单据类型', dataIndex: 'cCoVouchType', align: 'center', width: '10%' },
  { title: '对应单据号', dataIndex: 'cCoVouchID', align: 'center', width: '10%' },
  { title: '摘要', dataIndex: 'cDigest', align: 'center', width: '10%' },
  { title: '银行账号', dataIndex: 'cBankAccount', align: 'center', width: '10%' },
  { title: '币种名称', dataIndex: 'cexch_name', align: 'center', width: '10%' },
  { title: '汇率', dataIndex: 'iExchRate', align: 'center', width: '10%' },
  { title: '本币金额', dataIndex: 'iAmount', align: 'center', width: '10%' },
  { title: '原币金额', dataIndex: 'iAmount_f', align: 'center', width: '10%' },
  { title: '本币余额', dataIndex: 'iRAmount', align: 'center', width: '10%' },
  { title: '原币余额', dataIndex: 'iRAmount_f', align: 'center', width: '10%' },
  { title: '录入人', dataIndex: 'cOperator', align: 'center', width: '10%' },
  { title: '核销人', dataIndex: 'cCancelMan', align: 'center', width: '10%' },
  { title: '出纳签字人', dataIndex: 'cRPMan', align: 'center', width: '10%' },
  { title: '预收预付标志', dataIndex: 'bPrePay', align: 'center', width: '10%' },
  { title: '期初标志', dataIndex: 'bStartFlag', align: 'center', width: '10%' },
  { title: '订单号', dataIndex: 'cOrderNo', align: 'center', width: '10%' },
  { title: '结算科目编码', dataIndex: 'cCode', align: 'center', width: '10%' },
  { title: '预收付科目编码', dataIndex: 'cPreCode', align: 'center', width: '10%' },
  { title: '代付标志', dataIndex: 'iPayForOther', align: 'center', width: '10%' },
  { title: '结算单来源', dataIndex: 'cSrcFlag', align: 'center', width: '10%' },
  { title: '凭证线索号', dataIndex: 'cPzID', align: 'center', width: '10%' },
  { title: '应收应付标志', dataIndex: 'cFlag', align: 'center', width: '10%' },
  { title: '是否发送标志', dataIndex: 'bSend', align: 'center', width: '10%' },
  { title: '是否接收', dataIndex: 'bReceived', align: 'center', width: '10%' },
  { title: '结算科目项目', dataIndex: 'csItemCode', align: 'center', width: '10%' },
  { title: '主表标识', dataIndex: 'iID', align: 'center', width: '10%' },
  { title: '现结线索', dataIndex: 'cCancelNo', align: 'center', width: '10%' },
  { title: '对方银行', dataIndex: 'cBank', align: 'center', width: '10%' },
  { title: '本单位银行名称', dataIndex: 'cNatBank', align: 'center', width: '10%' },
  { title: '本单位银行账号', dataIndex: 'cNatBankAccount', align: 'center', width: '10%' },
  { title: '银行导入标志', dataIndex: 'bFromBank', align: 'center', width: '10%' },
  { title: '导出银行标志', dataIndex: 'bToBank', align: 'center', width: '10%' },
  { title: '银行确认标志', dataIndex: 'bSure', align: 'center', width: '10%' },
  { title: '单据模版号', dataIndex: 'VT_ID', align: 'center', width: '10%' },
  { title: '审核人', dataIndex: 'cCheckMan', align: 'center', width: '10%' },
  { title: '自定义项1', dataIndex: 'cDefine1', align: 'center', width: '10%' },
  { title: '自定义项2', dataIndex: 'cDefine2', align: 'center', width: '10%' },
  { title: '自定义项3', dataIndex: 'cDefine3', align: 'center', width: '10%' },
  { title: '自定义项4', dataIndex: 'cDefine4', align: 'center', width: '10%' },
  { title: '自定义项5', dataIndex: 'cDefine5', align: 'center', width: '10%' },
  { title: '自定义项6', dataIndex: 'cDefine6', align: 'center', width: '10%' },
  { title: '自定义项7', dataIndex: 'cDefine7', align: 'center', width: '10%' },
  { title: '自定义项8', dataIndex: 'cDefine8', align: 'center', width: '10%' },
  { title: '自定义项9', dataIndex: 'cDefine9', align: 'center', width: '10%' },
  { title: '自定义项10', dataIndex: 'cDefine10', align: 'center', width: '10%' },
  { title: '自定义项11', dataIndex: 'cDefine11', align: 'center', width: '10%' },
  { title: '自定义项12', dataIndex: 'cDefine12', align: 'center', width: '10%' },
  { title: '自定义项13', dataIndex: 'cDefine13', align: 'center', width: '10%' },
  { title: '自定义项14', dataIndex: 'cDefine14', align: 'center', width: '10%' },
  { title: '自定义项15', dataIndex: 'cDefine15', align: 'center', width: '10%' },
  { title: '自定义项16', dataIndex: 'cDefine16', align: 'center', width: '10%' },
  { title: '时间戳', dataIndex: 'Ufts', align: 'center', width: '10%' },
  { title: '项目名称', dataIndex: 'cItemName', align: 'center', width: '10%' },
  { title: '合同类型', dataIndex: 'cContractType', align: 'center', width: '10%' },
  { title: '合同号', dataIndex: 'cContractID', align: 'center', width: '10%' },
  { title: '数量', dataIndex: 'iAmount_s', align: 'center', width: '10%' },
  { title: '是否工作流控制', dataIndex: 'IsWfControlled', align: 'center', width: '10%' },
  { title: '来源', dataIndex: 'iSource', align: 'center', width: '10%' },
  { title: '发货单', dataIndex: 'sDLCode', align: 'center', width: '10%' },
  { title: '登记标志', dataIndex: 'RegisterFlag', align: 'center', width: '10%' },
  { title: '审核状态', dataIndex: 'iverifystate', align: 'center', width: '10%' },
  { title: '退回次数', dataIndex: 'ireturncount', align: 'center', width: '10%' },
  { title: '制单时间', dataIndex: 'dcreatesystime', align: 'center', width: '10%' },
  { title: '审核时间', dataIndex: 'dverifysystime', align: 'center', width: '10%' },
  { title: '修改时间', dataIndex: 'dmodifysystime', align: 'center', width: '10%' },
  { title: '修改人', dataIndex: 'cmodifier', align: 'center', width: '10%' },
  { title: '修改日期', dataIndex: 'dmoddate', align: 'center', width: '10%' },
  { title: '审核日期', dataIndex: 'dverifydate', align: 'center', width: '10%' },
  { title: '预算审批状态', dataIndex: 'ibg_overflag', align: 'center', width: '10%' },
  { title: '超预算审批人', dataIndex: 'cbg_auditor', align: 'center', width: '10%' },
  { title: '预算审批时间', dataIndex: 'cbg_audittime', align: 'center', width: '10%' },
  { title: '预算审批结果', dataIndex: 'controlresult', align: 'center', width: '10%' },
  { title: '预算项目编码', dataIndex: 'cbg_itemcode', align: 'center', width: '10%' },
  { title: '预算项目名称', dataIndex: 'cbg_itemname', align: 'center', width: '10%' },
  { title: '预算口径类型1编码', dataIndex: 'cbg_caliberkey1', align: 'center', width: '10%' },
  { title: '预算口径类型1名称', dataIndex: 'cbg_caliberkeyname1', align: 'center', width: '10%' },
  { title: '预算口径类型2编码', dataIndex: 'cbg_caliberkey2', align: 'center', width: '10%' },
  { title: '预算口径类型2名称', dataIndex: 'cbg_caliberkeyname2', align: 'center', width: '10%' },
  { title: '预算口径类型3编码', dataIndex: 'cbg_caliberkey3', align: 'center', width: '10%' },
  { title: '预算口径类型3名称', dataIndex: 'cbg_caliberkeyname3', align: 'center', width: '10%' },
  { title: '预算口径1编码', dataIndex: 'cbg_calibercode1', align: 'center', width: '10%' },
  { title: '预算口径1名称', dataIndex: 'cbg_calibername1', align: 'center', width: '10%' },
  { title: '预算口径2编码', dataIndex: 'cbg_calibercode2', align: 'center', width: '10%' },
  { title: '预算口径2名称', dataIndex: 'cbg_calibername2', align: 'center', width: '10%' },
  { title: '预算口径3编码', dataIndex: 'cbg_calibercode3', align: 'center', width: '10%' },
  { title: '预算口径3名称', dataIndex: 'cbg_calibername3', align: 'center', width: '10%' },
  { title: '是否预算控制', dataIndex: 'ibg_ctrl', align: 'center', width: '10%' },
  { title: '预算审批结果', dataIndex: 'cbg_auditopinion', align: 'center', width: '10%' },
  { title: '申请单号', dataIndex: 'cApplyCode', align: 'center', width: '10%' },
  { title: '凭证编号', dataIndex: 'cPZNum', align: 'center', width: '10%' },
  { title: '凭证日期', dataIndex: 'doutbilldate', align: 'center', width: '10%' },
  { title: '预算口径类型4编码', dataIndex: 'cbg_caliberkey4', align: 'center', width: '10%' },
  { title: '预算口径类型4名称', dataIndex: 'cbg_caliberkeyname4', align: 'center', width: '10%' },
  { title: '预算口径类型5编码', dataIndex: 'cbg_caliberkey5', align: 'center', width: '10%' },
  { title: '预算口径类型5名称', dataIndex: 'cbg_caliberkeyname5', align: 'center', width: '10%' },
  { title: '预算口径类型6编码', dataIndex: 'cbg_caliberkey6', align: 'center', width: '10%' },
  { title: '预算口径类型6名称', dataIndex: 'cbg_caliberkeyname6', align: 'center', width: '10%' },
  { title: '预算口径4编码', dataIndex: 'cbg_calibercode4', align: 'center', width: '10%' },
  { title: '预算口径4名称', dataIndex: 'cbg_calibername4', align: 'center', width: '10%' },
  { title: '预算口径5编码', dataIndex: 'cbg_calibercode5', align: 'center', width: '10%' },
  { title: '预算口径5名称', dataIndex: 'cbg_calibername5', align: 'center', width: '10%' },
  { title: '预算口径6编码', dataIndex: 'cbg_calibercode6', align: 'center', width: '10%' },
  { title: '预算口径6名称', dataIndex: 'cbg_calibername6', align: 'center', width: '10%' },
  { title: '打印次数', dataIndex: 'iPrintCount', align: 'center', width: '10%' },
  { title: '预定部门', dataIndex: 'cReserveDeptCode', align: 'center', width: '10%' },
  { title: '交易模式', dataIndex: 'bDealMode', align: 'center', width: '10%' },
  { title: '业务类型', dataIndex: 'iBusType', align: 'center', width: '10%' },
  { title: '付款类型', dataIndex: 'iPayType', align: 'center', width: '10%' },
  { title: '委托方编码', dataIndex: 'cagentcuscode', align: 'center', width: '10%' },
  { title: '单据条码', dataIndex: 'csysbarcode', align: 'center', width: '10%' },
  { title: '当前审批人', dataIndex: 'cCurrentAuditor', align: 'center', width: '10%' },
  { title: '日记账ID', dataIndex: 'lAcctID', align: 'center', width: '10%' },
  { title: '本币无税申请金额', dataIndex: 'iNotRateAmount', align: 'center', width: '10%' },
  { title: '无税申请金额', dataIndex: 'iNotRateAmount_f', align: 'center', width: '10%' },
  { title: '创建时间', dataIndex: 'CreateTime', width: '10%', align: 'center', scopedSlots: { customRender: 'CreateTime' } },
  { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    EditForm
  },
  mounted () {
    this.getDataList()
  },
  data () {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange (pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList () {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/OrderManagement/Ap_CloseBill/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          DeptId: this.DeptId,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected () {
      return this.selectedRowKeys.length > 0
    },
    handleAdd () {
      this.$refs.editForm.openForm(null, '新建收付款单主表信息')
    },
    handleEdit (id) {
      this.$refs.editForm.openForm(id, '编辑收付款单主表信息')
    },
    handleDelete (ids) {
      var thisObj = this
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
       return new Promise((resolve, reject) => {
          thisObj.$http.post('/OrderManagement/Ap_CloseBill/DeleteData', ids).then(resJson => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
        })
      })
    },
    timeFormat (val) { // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    }
  }
}
</script>
